//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		action:'register',
		pagetitle:'创建直播间',
		
	},
	onReady: function (){
		//获得粉丝消息弹窗(需要时开启)
		//this.ShowAuthM = this.selectComponent("#ShowAuthM");
		var fansinfo = wx.getStorageSync('userInfo');
		if(!fansinfo){
			//this.ShowAuthM.show();
		}
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (){
		var page=this;
		wx.setNavigationBarTitle({'title':page.data.pagetitle});
		app.util.get(app.access,function(pagedata){
			//console.log('pagedata');console.log(pagedata);
			page.setData({
				pagedata:pagedata,
				ShowAuthM:pagedata.show_setmember==2?true:false,
				action:app.access.action
			});
		});
	},
	start_time:function(e){
		var the = this
		var pagedata = the.data.pagedata
		pagedata.item.start_time = e.detail.value
		the.setData({
			'pagedata.item.start_time':pagedata.item.start_time
		})
	},
	end_time:function(e){
		var the = this
		var pagedata = the.data.pagedata
		pagedata.item.end_time = e.detail.value
		the.setData({
			'pagedata.item.end_time':pagedata.item.end_time
		})
	},
	closelikeChange:function(e) {
		var the = this
		var isshow = e.detail.value
		var pagedata=the.data.pagedata
		pagedata.item.closelike=e.detail.value;
		this.setData({
		  'pagedata.item.closelike': pagedata.item.closelike
		})
	},
	closegoodsChange:function(e) {
		var the = this
		var isshow = e.detail.value
		var pagedata=the.data.pagedata
		pagedata.item.closegoods=e.detail.value;
		this.setData({
		  'pagedata.item.closegoods': pagedata.item.closegoods
		})
	},
	closecommentChange:function(e) {
		var the = this
		var isshow = e.detail.value
		var pagedata=the.data.pagedata
		pagedata.item.closecomment=e.detail.value;
		this.setData({
		  'pagedata.item.closecomment': pagedata.item.closecomment
		})
	},
	onChooseAvatar:function(e){
		//获取头像
		var the=this;
		var avatarUrl= e.detail.avatarUrl
		the.setData({
			avatarUrl:avatarUrl
		})
		app.avatarUrl=avatarUrl
	},
	info_login:function(e){
		//根据openid为用户登陆，此处尝试获取用户信息
		var the=this;
		app.util.getUserInfo(e,function(res){
			if(res && res.userInfo){
				app.isgetUserInfo=true
				the.setData({
					ShowAuthM:false
				})
				the.onLoad();
			}else{
				return false;
			}
		});
	},
	mobile_login:function(e){
		//根据openid为用户登陆，此处尝试获取用户手机号
		var the = this
		var pagedata= the.data.pagedata
		app.util.post('core/member.login/wxapp_login/return_mobile=1',e.detail,function(res){
			the.setData({
				ShowAuthM:false
			})
		});
	},
	closeAuthM:function(){
		var the=this;
		the.setData({
			ShowAuthM:false
		})
	},
  	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	click_tab:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util.tab(data.params);
	},
	formSubmit:function(event){
		var the = this
		var pagedata = the.data.pagedata
		var value=event.detail.value;
		pagedata.item.name = value.name
		pagedata.item.anchor_name = value.anchor_name
		pagedata.item.anchor_wechat = value.anchor_wechat
		app.util.showLoading('创建中...');
		app.util.post('jy_weishop/sale.live_add/post/',pagedata.item,function(res){
			app.util.hideLoading();
			app.util.msg(res);
			the.onLoad();
		});
	},
	setcheck:function(){
		var the = this
		var pagedata = the.data.pagedata
		pagedata.item.check = pagedata.item.check?0:1
		the.setData({
			'pagedata.item.check':pagedata.item.check
		})
	},
	bindPickerChange:function(e){
		var the = this
		var pagedata = the.data.pagedata
		pagedata.item.type = e.detail.value
		the.setData({
			'pagedata.item.type':pagedata.item.type
		})
	},
	chooseshareimg: function (e) {
		var the = this
		var pagedata = the.data.pagedata
		var value = e.currentTarget.dataset
		app.util.image(function(res){
			pagedata.item.shareimg = res
			the.setData({
				'pagedata.item.shareimg':pagedata.item.shareimg
			})
		})
	},
	choosecover_img: function (e) {
		var the = this
		var pagedata = the.data.pagedata
		var value = e.currentTarget.dataset
		app.util.image(function(res){
			pagedata.item.cover_img = res
			the.setData({
				'pagedata.item.cover_img':pagedata.item.cover_img
			})
		})
	},
	choosefeeds_img: function (e) {
		var the = this
		var pagedata = the.data.pagedata
		var value = e.currentTarget.dataset
		app.util.image(function(res){
			pagedata.item.feeds_img = res
			the.setData({
				'pagedata.item.feeds_img':pagedata.item.feeds_img
			})
		})
	},
});